﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;

namespace NNLInterface
{
    public partial class rptProductInf : DevExpress.XtraReports.UI.XtraReport
    {
        public rptProductInf(DataTable dtMaster,DataTable dtDetail1,DataTable dtDetail2,DataTable dtDetail3,
                             DataTable dtDetail4,DataTable dtDetail5,DataTable dtDetail6,DataTable dtDetail7,
                             DataTable dtDetail8,DataTable dtDetail9)
        {
            InitializeComponent();



            //保持同一组在一页
            GroupHeader1.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;
            GroupHeader2.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;
            GroupHeader3.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;
            GroupHeader4.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;
            GroupHeader5.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;
            GroupHeader6.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;
            GroupHeader7.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;
            GroupHeader8.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;
            GroupHeader8.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;
            GroupHeader9.GroupUnion = DevExpress.XtraReports.UI.GroupUnion.WholePage;


            //页计数按组别来计数
            xrPageInfo1.RunningBand = GroupHeaderM;

            this.RequestParameters = false;
            DataSet ds = new DataSet();
            ds.Tables.Add(dtMaster);
            ds.Tables.Add(dtDetail1);
            ds.Tables.Add(dtDetail2);
            ds.Tables.Add(dtDetail3);

            ds.Tables.Add(dtDetail4);
            ds.Tables.Add(dtDetail5);
            ds.Tables.Add(dtDetail6);

            ds.Tables.Add(dtDetail7);
            ds.Tables.Add(dtDetail8);
            dtDetail9.DataSet.Tables.Remove(dtDetail9);
            ds.Tables.Add(dtDetail9);

            //建立主表与明细表间的关联关系,通过主表的NNL料号与从表中的
            DataColumn parentColumn1=ds.Tables["dtMaster"].Columns["NNLFGNo"];
            DataColumn parentColumn2 = ds.Tables["dtMaster"].Columns["CustCode"];
            DataColumn parentColumn3 = ds.Tables["dtMaster"].Columns["PartDetail"];
            DataColumn parentColumn4 = ds.Tables["dtMaster"].Columns["DrawVersion"];
            DataColumn parentColumn5 = ds.Tables["dtMaster"].Columns["MoNo"];

            //表1对应主表的关系
            DataColumn childColumn1 = ds.Tables[1].Columns["NNLFGNo"];
            DataColumn childColumn2 = ds.Tables[1].Columns["CustCode"];
            DataColumn childColumn3 = ds.Tables[1].Columns["PartDetail"];
            DataColumn childColumn4 = ds.Tables[1].Columns["DrawVersion"];
            DataColumn childColumn5 = ds.Tables[1].Columns["MoNo"];

            DataColumn[] parentColumns = new DataColumn[] { parentColumn1, parentColumn2, parentColumn3, parentColumn4, parentColumn5 };

            DataColumn[] childColumns = new DataColumn[] { childColumn1, childColumn2, childColumn3, childColumn4, childColumn5};

            DataRelation dsdr1 = new DataRelation("fk_1", parentColumns, childColumns, false);
            ds.Relations.Add(dsdr1);


            //表2对应主表的关系
            childColumn1 = ds.Tables[2].Columns["NNLFGNo"];
            childColumn2 = ds.Tables[2].Columns["CustCode"];
            childColumn3 = ds.Tables[2].Columns["PartDetail"];
            childColumn4 = ds.Tables[2].Columns["DrawVersion"];
            childColumn5 = ds.Tables[2].Columns["MoNo"];


            childColumns = new DataColumn[] { childColumn1, childColumn2, childColumn3, childColumn4, childColumn5 };

            DataRelation dsdr2 = new DataRelation("fk_2", parentColumns, childColumns, false);
            ds.Relations.Add(dsdr2);

            //表3对应主表的关系
            childColumn1 = ds.Tables[3].Columns["NNLFGNo"];
            childColumn2 = ds.Tables[3].Columns["CustCode"];
            childColumn3 = ds.Tables[3].Columns["PartDetail"];
            childColumn4 = ds.Tables[3].Columns["DrawVersion"];
            childColumn5 = ds.Tables[3].Columns["MoNo"];


            childColumns = new DataColumn[] { childColumn1, childColumn2, childColumn3, childColumn4, childColumn5 };

            DataRelation dsdr3 = new DataRelation("fk_3", parentColumns, childColumns, false);
            ds.Relations.Add(dsdr3);

            //表4对应主表的关系
            childColumn1 = ds.Tables[4].Columns["NNLFGNo"];
            childColumn2 = ds.Tables[4].Columns["CustCode"];
            childColumn3 = ds.Tables[4].Columns["PartDetail"];
            childColumn4 = ds.Tables[4].Columns["DrawVersion"];
            childColumn5 = ds.Tables[4].Columns["MoNo"];


            childColumns = new DataColumn[] { childColumn1, childColumn2, childColumn3, childColumn4, childColumn5 };

            DataRelation dsdr4 = new DataRelation("fk_4", parentColumns, childColumns, false);
            ds.Relations.Add(dsdr4);

            //表5对应主表的关系
            childColumn1 = ds.Tables[5].Columns["NNLFGNo"];
            childColumn2 = ds.Tables[5].Columns["CustCode"];
            childColumn3 = ds.Tables[5].Columns["PartDetail"];
            childColumn4 = ds.Tables[5].Columns["DrawVersion"];
            childColumn5 = ds.Tables[5].Columns["MoNo"];


            childColumns = new DataColumn[] { childColumn1, childColumn2, childColumn3, childColumn4, childColumn5 };

            DataRelation dsdr5 = new DataRelation("fk_5", parentColumns, childColumns, false);
            ds.Relations.Add(dsdr5);

            //表6对应主表的关系
            childColumn1 = ds.Tables[6].Columns["NNLFGNo"];
            childColumn2 = ds.Tables[6].Columns["CustCode"];
            childColumn3 = ds.Tables[6].Columns["PartDetail"];
            childColumn4 = ds.Tables[6].Columns["DrawVersion"];
            childColumn5 = ds.Tables[6].Columns["MoNo"];


            childColumns = new DataColumn[] { childColumn1, childColumn2, childColumn3, childColumn4, childColumn5 };

            DataRelation dsdr6 = new DataRelation("fk_6", parentColumns, childColumns,false);
            ds.Relations.Add(dsdr6);

            //表7对应主表的关系
            childColumn1 = ds.Tables[7].Columns["NNLFGNo"];
            childColumn2 = ds.Tables[7].Columns["CustCode"];
            childColumn3 = ds.Tables[7].Columns["PartDetail"];
            childColumn4 = ds.Tables[7].Columns["DrawVersion"];
            childColumn5 = ds.Tables[7].Columns["MoNo"];


            childColumns = new DataColumn[] { childColumn1, childColumn2, childColumn3, childColumn4, childColumn5 };

            DataRelation dsdr7 = new DataRelation("fk_7", parentColumns, childColumns, false);
            ds.Relations.Add(dsdr7);


            //表8对应主表的关系
            childColumn1 = ds.Tables[8].Columns["NNLFGNo"];
            childColumn2 = ds.Tables[8].Columns["CustCode"];
            childColumn3 = ds.Tables[8].Columns["PartDetail"];
            childColumn4 = ds.Tables[8].Columns["DrawVersion"];
            childColumn5 = ds.Tables[8].Columns["MoNo"];


            childColumns = new DataColumn[] { childColumn1, childColumn2, childColumn3, childColumn4, childColumn5 };

            DataRelation dsdr8 = new DataRelation("fk_8", parentColumns, childColumns, false);
            ds.Relations.Add(dsdr8);


            //表9对应主表的关系
            childColumn1 = ds.Tables[9].Columns["NNLFGNo"];
            childColumn2 = ds.Tables[9].Columns["CustCode"];
            childColumn3 = ds.Tables[9].Columns["PartDetail"];
            childColumn4 = ds.Tables[9].Columns["DrawVersion"];
            childColumn5 = ds.Tables[9].Columns["MoNo"];

            DataColumn[] parentColumnsM = new DataColumn[] { parentColumn1, parentColumn2, parentColumn3, parentColumn4, parentColumn5 };


            childColumns = new DataColumn[] { childColumn1, childColumn2, childColumn3, childColumn4, childColumn5 };

            DataRelation dsdr9 = new DataRelation("fk_9", parentColumnsM, childColumns, false);
            ds.Relations.Add(dsdr9);



            this.DataSource = ds;

            DetailReport1.DataMember = "fk_1";
            DetailReport1.DataSource = ds;

            DetailReport2.DataMember = "fk_2";
            DetailReport2.DataSource = ds;

            DetailReport3.DataMember = "fk_3";
            DetailReport3.DataSource = ds;

            DetailReport4.DataMember = "fk_4";
            DetailReport4.DataSource = ds;

            DetailReport5.DataMember = "fk_5";
            DetailReport5.DataSource = ds;

            DetailReport6.DataMember = "fk_6";
            DetailReport6.DataSource = ds;

            DetailReport7.DataMember = "fk_7";
            DetailReport7.DataSource = ds;

            DetailReport8.DataMember = "fk_8";
            DetailReport8.DataSource = ds;

            DetailReport9.DataMember = "fk_9";
            DetailReport9.DataSource = ds;


            this.GroupHeaderM.GroupFields.AddRange(new DevExpress.XtraReports.UI.GroupField[] {
            new DevExpress.XtraReports.UI.GroupField("NNLFGNo", DevExpress.XtraReports.UI.XRColumnSortOrder.Ascending),
            new DevExpress.XtraReports.UI.GroupField("CustCode", DevExpress.XtraReports.UI.XRColumnSortOrder.Ascending),
            new DevExpress.XtraReports.UI.GroupField("PartDetail", DevExpress.XtraReports.UI.XRColumnSortOrder.Ascending),
            new DevExpress.XtraReports.UI.GroupField("DrawVersion", DevExpress.XtraReports.UI.XRColumnSortOrder.Ascending),
            new DevExpress.XtraReports.UI.GroupField("MoNo", DevExpress.XtraReports.UI.XRColumnSortOrder.Ascending)});

            //以下为数据绑定
            //设定主表的数据绑定
            this.lblNNLFGNo.DataBindings.Add("Text", ds, "dtMaster.NNLFGNo");
            this.lblCustCode.DataBindings.Add("Text", ds, "dtMaster.CustCode");
            this.lblVersion.DataBindings.Add("Text", ds, "dtMaster.DrawVersion");
            this.lblPartDetail.DataBindings.Add("Text", ds, "dtMaster.PartDetail");
            this.lblMoNo.DataBindings.Add("Text", ds, "dtMaster.MoNo");
            this.lblChecker.DataBindings.Add("Text", ds, "dtMaster.Checker");
            this.lblEngineer.DataBindings.Add("Text", ds, "dtMaster.Engineer");

            //以下为表1的数据的绑定(端子与电线(或其它物料)间的铆压)
            this.lbl11.DataBindings.Add("Text", ds, "fk_1.货品规格");
            this.lbl12.DataBindings.Add("Text", ds, "fk_1.材料规格");
            this.lbl13.DataBindings.Add("Text", ds, "fk_1.外径");
            this.lbl14.DataBindings.Add("Text", ds, "fk_1.导体结构");
            this.lbl15.DataBindings.Add("Text", ds, "fk_1.拉力");
            this.lbl16.DataBindings.Add("Text", ds, "fk_1.特殊规格");
            this.lbl17.DataBindings.Add("Text", ds, "fk_1.拉力3");
            this.lbl18.DataBindings.Add("Text", ds, "fk_1.导体铆高");
            this.lbl19.DataBindings.Add("Text", ds, "fk_1.导体铆宽");
            this.lbl110.DataBindings.Add("Text", ds, "fk_1.绝缘铆高");
            this.lbl111.DataBindings.Add("Text", ds, "fk_1.绝缘铆宽");
            this.lbl112.DataBindings.Add("Text", ds, "fk_1.模具储位号");
            this.lbl113.DataBindings.Add("Text", ds, "fk_1.锡棒规格");
            this.lbl114.DataBindings.Add("Text", ds, "fk_1.备注");

            //以下为表2的数据的绑定(电线印字)
            this.lbl21.DataBindings.Add("Text", ds, "fk_2.货品规格");
            this.lbl22.DataBindings.Add("Text", ds, "fk_2.供应商");
            this.lbl23.DataBindings.Add("Text", ds, "fk_2.印字内容");
            this.lbl24.DataBindings.Add("Text", ds, "fk_2.电线OD");
            this.lbl25.DataBindings.Add("Text", ds, "fk_2.备注");


            //以下为表3的数据绑定（电性测试）
            this.lbl31.DataBindings.Add("Text", ds, "fk_3.DC高压");
            this.lbl32.DataBindings.Add("Text", ds, "fk_3.AC高压");
            this.lbl33.DataBindings.Add("Text", ds, "fk_3.短断路");
            this.lbl34.DataBindings.Add("Text", ds, "fk_3.绝缘电阻");
            this.lbl35.DataBindings.Add("Text", ds, "fk_3.导通电阻");

            this.lbl36.DataBindings.Add("Text", ds, "fk_3.漏电流");
            this.lbl37.DataBindings.Add("Text", ds, "fk_3.极性导通测试");
            this.lbl38.DataBindings.Add("Text", ds, "fk_3.测试设备名称");
            this.lbl39.DataBindings.Add("Text", ds, "fk_3.简易治具编号");
            this.lbl310.DataBindings.Add("Text", ds, "fk_3.1比1测试治具编号");
            this.lbl311.DataBindings.Add("Text", ds, "fk_3.备注");


            //以下为表4的数据绑定(端子的插拔力/其它插拔力)
            this.lbl41.DataBindings.Add("Text", ds, "fk_4.端子规格");
            this.lbl42.DataBindings.Add("Text", ds, "fk_4.公插规格");
            this.lbl43.DataBindings.Add("Text", ds, "fk_4.第一次插入力");
            this.lbl44.DataBindings.Add("Text", ds, "fk_4.第一次拔出力");
            this.lbl45.DataBindings.Add("Text", ds, "fk_4.第六次拔出力");
            this.lbl46.DataBindings.Add("Text", ds, "fk_4.备注");


            //以下为表5刺破型端子铆压要求
            this.lbl51.DataBindings.Add("Text", ds, "fk_5.货品规格");
            this.lbl52.DataBindings.Add("Text", ds, "fk_5.导体规格");
            this.lbl53.DataBindings.Add("Text", ds, "fk_5.电线OD");
            this.lbl54.DataBindings.Add("Text", ds, "fk_5.铆压深度");
            this.lbl55.DataBindings.Add("Text", ds, "fk_5.垂直拉力");
            this.lbl56.DataBindings.Add("Text", ds, "fk_5.水平拉力");
            this.lbl57.DataBindings.Add("Text", ds, "fk_5.刀片编号");
            this.lbl58.DataBindings.Add("Text", ds, "fk_5.备注");


            //以下为表6端子与P架间的保持力
            this.lbl61.DataBindings.Add("Text", ds, "fk_6.P架规格");
            this.lbl62.DataBindings.Add("Text", ds, "fk_6.保持力");


            //以下为表7束带绷张力
            this.lbl71.DataBindings.Add("Text", ds, "fk_7.货品规格");
            this.lbl72.DataBindings.Add("Text", ds, "fk_7.束线力");
            this.lbl73.DataBindings.Add("Text", ds, "fk_7.备注");


            //以下为表8其它设备模具清单
            this.lbl81.DataBindings.Add("Text", ds, "fk_8.其它模治具名称");
            this.lbl82.DataBindings.Add("Text", ds, "fk_8.治具编号");
            this.lbl83.DataBindings.Add("Text", ds, "fk_8.使用工序");


            //以下为表9包装
            this.lbl91.DataBindings.Add("Text", ds, "fk_9.外箱编码及规格");
            this.lbl92.DataBindings.Add("Text", ds, "fk_9.胶袋编码及规格");
            this.lbl93.DataBindings.Add("Text", ds, "fk_9.UL标签编码及规格");
            this.lbl94.DataBindings.Add("Text", ds, "fk_9.UL标签张数");
            this.lbl95.DataBindings.Add("Text", ds, "fk_9.刀卡规格");
            this.lbl96.DataBindings.Add("Text", ds, "fk_9.隔板规格");
            this.lbl97.DataBindings.Add("Text", ds, "fk_9.隔板位置");
            this.lbl98.DataBindings.Add("Text", ds, "fk_9.每把(包)数");
            this.lbl99.DataBindings.Add("Text", ds, "fk_9.层/把每箱");
            this.lbl910.DataBindings.Add("Text", ds, "fk_9.每箱总数");
            this.lbl911.DataBindings.Add("Text", ds, "fk_9.单重");
            this.lbl912.DataBindings.Add("Text", ds, "fk_9.毛重");
            this.lbl913.DataBindings.Add("Text", ds, "fk_9.尾箱填充物");
            this.lbl914.DataBindings.Add("Text", ds, "fk_9.捆扎包材及方式");
            this.lbl915.DataBindings.Add("Text", ds, "fk_9.备注");


            this.picsinglechengpic.DataBindings.Add("Image", ds, "fk_9.SingleChengPic");
            this.picsinglePackpic.DataBindings.Add("Image", ds, "fk_9.SinglePackPic");

            //this.picsinglechengpic.DataBindings.Add("Image", ds, "fk_9.singlechengpic");
            //this.picsinglePackpic.DataBindings.Add("Image", ds, "fk_9.singlePackpic");

            
        }

        private void SetDataBing()
        {
            



        }

        private void picsinglechengpic_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            //2013-06-28一定要注意字段名称的大小写，否则会取不到数据，会报错
            string path = Convert.ToString(DetailReport9.GetCurrentColumnValue("SingleChengPic").ToString());
            if (path != "")
            {
                if (System.IO.File.Exists(path))
                {
                    Image im = new Bitmap(path, true);
                    picsinglechengpic.Image = im;
                }
            }
        }

        private void picsinglePackpic_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            string path = Convert.ToString(DetailReport9.GetCurrentColumnValue("SinglePackPic").ToString());
            //System.Windows.Forms.MessageBox.Show(path);
            if (path != "")
            {
                if (System.IO.File.Exists(path))
                {
                    Image im = new Bitmap(path, true);
                    picsinglePackpic.Image = im;
                }
            }
        }



        //private void xrPictureBox1_BeforePrint_1(object sender, System.Drawing.Printing.PrintEventArgs e)
        //{
        //    //string path = @"c:\test.jpg";
        //    string path = Convert.ToString(DetailReport1.GetCurrentColumnValue("pic"));
        //    //DataRow dr = (DataRow)this.GetCurrentRow();
        //    if (path != "")
        //    {
        //        Image im = new Bitmap(path, true);
        //        xrPictureBox1.Image = im;
        //    }

        //    //     Dim path As String = (CStr(Me.GetCurrentColumnValue("pic")))
        //    //If path IsNot Nothing Then
        //    //    Dim im As Image = New Bitmap(path, True)
        //    //    CType(sender, XRPictureBox).Image = im
        //    //End If
        //}
    }
}
